import sqlite3

# conn = sqlite3.connect('test.db')
#
# curse= conn.cursor()  #句柄
#
#
# #创建表
#
# sql ='''
#   create table if not  exists rank_info2 (
#    rank_id varchar primary key not null ,
#    collage_name varchar not null ,
#    core varchar not null
#   )
# '''
# curse.execute(sql)


def  createTableIfExists( curse):
    sql = '''
      create table if not  exists rank_info2 (
       rank_id varchar primary key not null ,
       collage_name varchar not null ,
       core varchar not null
      )
    '''
    curse.execute(sql)


def connection():
    conn = sqlite3.connect('test.db')
    curse = conn.cursor()  # 句柄
    createTableIfExists(curse)
    # print("创建数据库成功!!")
    return conn,curse


#插入数据成员,函数
def insertTable(rank_id,collage_name,core):

    #1.连接
    conn,curse=connection()

    curse.execute("insert into rank_info2 values (?,?,?)",(rank_id,collage_name,core))
    print("插入成功!!")
    conn.commit()


#查询数据
def selectTable():
    # 1.连接
    conn, curse = connection()
    info= curse.execute("select * from rank_info2")
    conn.commit()
    return info #返回的是个数组


#关闭
def close():
    conn, curse = connection()
    conn.close()